/*
 *  Copyright (C) 2011 JiangHongTiao <jjurco.sk@@@gmail.com>
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package sk.lieskove301.jianghongtiao.liaad.prisoner.statistics.charts;


import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JPanel;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import sk.lieskove301.jianghongtiao.liaad.prisoner.gene.GeneticInfo;
import sk.lieskove301.jianghongtiao.liaad.prisoner.statistics.AgentsTimelineUnit;

/**
 * Date of create: May 15, 2011
 *
 * @author JiangHongTiao <jjurco.sk_gmail.com>
 * @version 2011.0515
 */
public abstract class AbstractChart extends ApplicationFrame {
    
    private String title = "lala";

    public AbstractChart(String title) {
        super(title);
        this.title = title;
    }

    protected abstract XYDataset createDataset(
            List<Map<String, AgentsTimelineUnit>> agents);

    protected abstract JFreeChart createChart(XYDataset dataset);

    public JPanel createPanel(List<Map<String, AgentsTimelineUnit>> agents) {
        JFreeChart chart = createChart(createDataset(agents));
        try {
            if(false)ChartUtilities.saveChartAsPNG(new File(title+".png"), chart, 3000, 5000);
        } catch (IOException ex) {
            Logger.getLogger(AbstractChart.class.getName()).
                    log(Level.SEVERE, null, ex);
        }
        ChartPanel panel = new ChartPanel(chart);
        panel.setFillZoomRectangle(true);
        panel.setMouseWheelEnabled(true);
        return panel;
    }

    public void main(List<Map<String, AgentsTimelineUnit>> agents) {
        ChartPanel chartPanel = (ChartPanel) createPanel(agents);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(chartPanel);

        this.pack();
        RefineryUtilities.centerFrameOnScreen(this);
        this.setVisible(true);
    }

}
